<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

jimport( 'joomla.application.component.view' );

/**
 * @package Joomla
 * @subpackage JobBoard
 */
class JobBoardViewJAJobs extends JView
{
    /**
     * Display the view
     */
    function display($tmpl = null){    
    	$this->assign('Itemid', JRequest::getInt('Itemid'));
    	/* Set page title */
    	$page_title = getPageTitleFromMenu();
    	$config = new JConfig();
		$document = JFactory::getDocument();
    	
		$this->layout = JRequest::getVar('layout', 'jalist');
		if($this->layout=='jalist') $this->layout = '';
		elseif ($this->layout=='jobalert_result'){
			$cid = JRequest::getVar('cid', array(0), '', 'array');
			$this->layout .= "&cid[]=".@$cid[0];
		}
		
		$Itemid = get_Itemid(array('option'=>'com_jajobboard', 'view'=>'jajobs', 'layout'=>'jalist'));
		if(!$Itemid || $Itemid == 9999) $Itemid = JRequest::getInt('Itemid');
        $this->assignRef('Itemid', $Itemid );
               
    	switch ($this->getLayout())
        {        	
        	case 'jaview':			
        		$this->multi_view();

        		/* Set page title */		       	
				if (!$page_title){			
					if (count($this->items)==1){
						$page_title = $this->items[0]->title;
						setPageTitle(array("job_page_title", "job_page_keyword", "job_page_description"), $this->items[0], "{JOB_TITLE}");
					}
					else{
						$page_title = JText::_('View details list of jobs');						
						setPageTitle(array("job_page_title", "job_page_keyword", "job_page_description"), null, JText::_("View details list of jobs") );
					}
				}else $document->setTitle($page_title.' - '.$config->sitename);
				/* End: Set page title */
        		
        		break;
        		
        	case 'myjobs':
        		$this->show_my_jobs();
        		$this->setLayout('jalist');
        		
        		/* Set page title */		       	
				if (!$page_title){			
					if (count($this->all_items)==1){
						$page_title = $this->all_items[0]->title;
					}
					elseif($this->profile){
						$jobs = $this->profile;
					    $jobs->title = $this->profile->company;
					    $jobs->job_detail = "";					    
						setPageTitle(array("job_employer_title", "job_employer_keyword", "job_employer_description"), $jobs, JText::_('Job posting by'). ' ' . $this->profile->company );
					}
				}else $document->setTitle($page_title.' - '.$config->sitename);				
				/* End: Set page title */
        		
        		break;
        		
        	case 'jajobseekerlist':        		
        		$this->show_list_job();
        		if (!$page_title)
					$page_title = JText::_('Job').'/'.JText::_('Job seeker favourite');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;
        		
        	case 'filter_job_list':
        		$this->show_result_filter_job();
        		if (!$page_title)
					$page_title = JText::_('Filter Jobs');
				$document->setTitle($page_title.' - '.$config->sitename);
				JRequest::setVar("layout", "jalist");
        		break;
        	case 'jobalert_result':
        		$this->show_result_jobalert();
        		if (!$page_title)
					$page_title = JText::_('Job list');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;
        	case 'jaform':
        		$this->edit(false);
        		if (!$page_title)
					$page_title = JText::_('Job form');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;    
        				
			case 'japremiumform':
        		$this->edit(true);
        		if (!$page_title)
					$page_title = JText::_('Job form');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;   
			case 'suggesturl':
				$this->suggesturl();
				break;	     	
        	case 'duplicate':        	   
        		$this->edit(false);
        		if (!$page_title)
					$page_title = JText::_('Job form');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break; 
        	case 'multi_view':
        		$this->multi_view();
        		if (!$page_title)
        		{
					$page_title = JText::_('View detail');
					if (count($this->items)==1)
						$page_title .= ' - '.$this->items[0]->title;
        		}
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;
        	case 'display_capcha':
        		$this->displaycaptchaaddnew();
        		break;
        	case 'jasearchform':        		
        		$this->display_searchform();
        		if (!$page_title){
					$page_title = JText::_('Search job');
					setPageTitle(array("job_search_title", "job_search_keyword", "job_search_description"), null, $page_title );
        		}else$document->setTitle($page_title.' - '.$config->sitename);
        		break;        	        	
        	case 'searchform_result':
        		$this->show_result_filter_job();
        		if (!$page_title)
					$page_title = JText::_('Search job');
				$document->setTitle($page_title.' - '.$config->sitename);
        		break;
        	case 'job_list_via_profiles':
        		$this->job_list_via_profiles();
        		$this->setLayout('jalist');
        		break;
        	case 'jauploadfile':
        		$this->displayUploadFileForm();
        		break;
        	case 'jauploadfilepath':
        		$this->displayUploadFilePath();
        		break;
        	
        	case 'jalistblank':
        		break;
        		
        	default:        		
        		$this->setLayout('jalist');
        		$this->show_list_job();
        		
        		if (!$page_title){					
					setPageTitle(array("job_list_title", "job_list_keyword", "job_list_description"), null, JText::_('Job list'));
					$uid = JRequest::getVar('uid');
					if (isset($this->profile) && $uid) {
					    $jobs = $this->profile;
					    $jobs->title = $this->profile->company;
					    $jobs->job_detail = "";					    
						setPageTitle(array("job_employer_title", "job_employer_keyword", "job_employer_description"), $jobs, JText::_('Job posting by'). ' ' . $this->profile->company );						
					}
        		}else $document->setTitle($page_title.' - '.$config->sitename);    		
        }
       
        parent::display($tmpl);        
  	}
      	
  	/**
  	* Display List of items
  	*/
  	function show_list_job(){  	
  		global $mainframe, $option, $jbconfig, $permission;       
        
  		$user_id = JRequest::getVar('uid', '');
  		$where_more = '';
		if(!$user_id){
        	$user = JFactory::getUser();
        	$user_id = $user->id;        	
        }
        else{
        	$user = JFactory::getUser();
        	$db = JFactory::getDBO();
        	$user_id = str_replace('()','.',$user_id);
        	$query = "SELECT * FROM #__users WHERE username='$user_id'";
        	$db->setQuery($query);
        	$result = $db->loadObject();
        	if ($result)
        		$user_id = $result->id;
        	
        }
        $profile = getCustomerProfile($user_id);
        $this->assign('profile', $profile);
  		
  		/* Check permission */
  		checkPermission('view_list_jobs');
  		
  		
  		// get data items
        $model = &$this->getModel();   
        
        
        /* Get field select list */
  		$fieldEditList = $model->getEditFieldList(' and f.frontend_hidden=0 ');
  		$this->assignRef('allFields', $fieldEditList);
  		
       	$lists = $this->_getViewLists($fieldEditList);  
       	$this->assignRef('lists', $lists);
       	

  		/* Get items list */ 		
        $limitstart = JRequest::getInt('limitstart', 0);
		$limit		= JRequest::getInt('limit', $jbconfig['posts']->get('display_num', 20));
        
		$where_more  = '';		
        $where_more .= ' AND a.status=\'Approved\' ';
        $where_more .= ' AND a.effected_date<=now()';
       	$where_more .= ' AND ( 
       							( a.expiry_date >= now() ) OR 
       							( 	a.expiry_date is NULL  AND   ( 
       									( DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_display_days', 30). ' DAY) >= now()  AND a.is_hotjob=0) OR
       									( DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_show_days_elapsed', 30). ' DAY) >= now()  AND a.is_hotjob=1) 
       								) 
       							)
       						)';
               
  		$user_id = JRequest::getVar('uid', '');
		if($user_id){
			$user = JFactory::getUser($user_id);
        	if($user->id){
        		$where_more .= " and a.user_id=".(int)$user->id;
        	}
        }
       
        
        if($this->getLayout()=='jajobseekerlist'){
        	$items_id = $model->get_save_jobs_list();
        	if ($items_id==''||$items_id==null) $items_id='0';
        	$where_more .= " and a.id in ($items_id)";
        }
           
        
		//Job type
  		$jobtype = JRequest::getVar('jobtype', '');
        if($jobtype){
			$where_more .= " and a.job_type=".(int)$jobtype;
        }
        
        $all_items = $model->getItems($where_more, $limit, $limitstart);  
        $this->assignRef('all_items', $all_items);
        $item_notes = $model->getItemNotes($all_items);
        $this->assignRef('item_notes', $item_notes);
        
        /* Paging */
       	$pagination = &$this->get('Pagination');  
       	
       	$this->assignRef('pagination', $pagination);
        
        /* Get field list */
        $where_more = '';
		if(!$mainframe->isAdmin()){
			$where_more = " and fl.admin_only!=1";
		}		
       	$fieldList = $model->getFieldList($where_more);
		$this->assignRef('fieldlist', $fieldList);		
		
		$ordering = true;           
        $this->assignRef('ordering', $ordering );                
  	}
  	
  	function &_getViewLists($fieldList)
	{
		checkPermission('view_list_jobs');
		global $mainframe, $option, $jbconfig;
		
		$db = &JFactory::getDBO();
		
        /*$lists['filter_status']	= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_status",	'filter_status',		'',	'cmd' );
        if($lists['filter_status']=='') $lists['filter_status'] = -1;*/
		$lists['filter_order']		= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order",		'filter_order',		"a.".$jbconfig['posts']->get('filter_order'),	'cmd' );
		$lists['filter_order_Dir']	= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order_Dir",	'filter_order_Dir',	$jbconfig['posts']->get('filter_order_Dir'),	'word' );	
		$lists['order']	= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order", 'filter_order',	"a.".$jbconfig['posts']->get('filter_order'), 'cmd' );
		$lists['order_Dir']	= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order_Dir", 'filter_order_Dir',	$jbconfig['posts']->get('filter_order_Dir'), 'word' );
	

        // filter_state
        $lists['option']    = $option;

		return $lists;
	}
  	
	function show_my_jobs(){
		global $mainframe, $option, $jbconfig;
		checkPermission('view_list_jobs');
		  
		$where_more = '';
		
		$user_id = JRequest::getVar('uid', '');
		
		if( JRequest::getVar("employerid", "") != "" ){
			$user_id = getItemByFieldName("users", "id", JRequest::getVar("employerid", "") );			
			$user_id = $user_id[0]->username;			
		}
		
		if(!$user_id){
        	$user = JFactory::getUser();
        	$user_id = $user->id;        	   	
        }
        
        else{
        	$user = JFactory::getUser();
        	$db = JFactory::getDBO();
        	$user_id = str_replace('()','.',$user_id);
        	$query = "SELECT * FROM #__users WHERE username='$user_id'";
        	$db->setQuery($query);
        	$result = $db->loadObject();
        	if ($result)
        		$user_id = $result->id;
        	if ($user->id != $user_id)
        	{
	        	$where_more .= " and a.status='Approved' ";
	    		$where_more .= ' AND a.effected_date<=now()';
       			$where_more .= ' AND ( 
		       							( a.expiry_date >= now() ) OR 
		       							( 	a.expiry_date is NULL  AND   ( 
		       									( DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_display_days', 30). ' DAY) >= now()  AND a.is_hotjob=0) OR
		       									( DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_show_days_elapsed', 30). ' DAY) >= now()  AND a.is_hotjob=1) 
		       								) 
		       							)
		       						)';
        	}
        }
        $user = JFactory::getUser($user_id);
    	
        //if($user->usertype=='Administrator') checkPermission_Administrator('job');
        $this->assign('user', $user);
		
        $profile = getCustomerProfile($user_id);
        $this->assign('profile', $profile);
        
		    

  		$params = &$mainframe->getParams();
  		$this->assign('params', $params);
  		 
        // get data items
        $model = &$this->getModel();               
        
        $where_more .= " and a.user_id=".(int)$user_id;
        
        $limitstart = JRequest::getInt('limitstart', 0);
		$limit		= JRequest::getInt('limit', $jbconfig['posts']->get('display_num', 20));
		
       	$all_items = $model->getItems($where_more, $limit, $limitstart);       	
       	
       	$fieldEditList = $model->getEditFieldList(' and f.frontend_hidden=0');
       	
       	global $mainframe;
       	if(!$mainframe->isAdmin()){
			$where_more = " and fl.admin_only!=1";
		}
       	$fieldList = $model->getFieldList();

		$pagination = &$this->get('Pagination');       
        
        $lists = $this->_getViewLists($fieldEditList);        
        
        $ordering = true;      
        $this->assignRef('all_items', $all_items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('fieldlist', $fieldList);
        $this->assignRef('lists', $lists);
        $this->assignRef('ordering', $ordering );
	}
	
  	function getAdminList()
  	{  		
  		$items = &$this->get('AdminItems');
		$pagination = &$this->get('Pagination');
        $fieldList = &$this->get('FieldList');
        $lists = $this->_getViewLists($fieldList);
        $ordering = true;
        $table_name = "jos_ja_jobs";
        $modsearch = $this->get('SearchParams');
        
        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('fieldlist', $fieldList);
        $this->assignRef('lists', $lists);
        $this->assignRef('ordering', $ordering );
        $this->assignRef('table_name', $table_name );
        $this->assignRef('modsearch', $modsearch);
  	}  	
  	  	
  	/**
  	* Display edit form
  	*/
  	function edit($premium=false, $postback = true){
  		global $jbconfig, $mainframe, $option;
		$task = JRequest::getVar('do');
		$layout = $this->getLayout();
  		if(!$premium)	checkPermission('standard_post_job');
  		else checkPermission('premium_post_job');
  		  		  		    	
    	$is_hotjob = $premium;
        $user = &JFactory::getUser();
        
        $item = $this->get('Item');
        
        if ($this->getLayout()=='duplicate'){
            $item->id = null;
            $this->setLayout('jaform');
        }
        
        if ($item->id)    	$init_status = $item->status;
        
//        if(!$premium && !$item->id && $jbconfig['billing']->get('posting_fee_enabled', 0)){
//        	        
//        	$account = getAccountByUserID($user->id);
//        	if(!$account || (int)$account->standard_posts_balance<1){
//        		$this->assign('goto_buynow', true);
//        		return ;
//        	}
//        }
        
        if ($layout!='duplicate')
        {
	        if(!$premium && !$item->id && $jbconfig['billing']->get('posting_fee_enabled', 0)){
	        	        
	        	$account = getAccountByUserID($user->id);
	        	if(!$account || (int)$account->standard_posts_balance<1){
	        		$this->assign('goto_buynow', true);
	        		return ;
	        	}
	        }
	        
	        if($premium && !$item->id && $jbconfig['billing']->get('premium_posting_fee_enabled', 0)){
	        	        
	        	$account = getAccountByUserID($user->id);
	        	if(!$account || (int)$account->premium_posts_balance<1){
	        		$this->assign('goto_buynow', true);
	        		return ;
	        	}
	        	
	        }
        }
        else 
        {
        	$item->temp_title = JRequest::getVar('temp_title')?JRequest::getVar('temp_title'):$item->title;
        	$account = getAccountByUserID($user->id);
        	if(!$account || (int)$account->standard_posts_balance<1)
        		$can_post_standard_job = 'disabled';
        	else 
        		$can_post_standard_job = '';
        	if(!$account || (int)$account->premium_posts_balance<1)
        		$can_post_premium_job = 'disabled';
        	else 		
        		$can_post_premium_job = '';
        		
        	if (($can_post_standard_job!='')&&($can_post_premium_job!=''))
        	{
        		$this->assign('goto_buynow', true);
	        		return ;
        	}
        	$this->assignRef('can_post_standard_job', $can_post_standard_job);
        	$this->assignRef('can_post_premium_job', $can_post_premium_job);
        	
        }

        if($postback){
            $post    = JRequest::get('request', JREQUEST_ALLOWHTML);
            $item->bind($post);
        }
        
        $temp = $this->getModel('jajobs');
        $fieldList = $temp->getEditFieldList(' and f.frontend_hidden=0');
		$suggestURL = $this->get('SuggestURL');               
        
        $this->assignRef('init_status', $init_status);
		$this->assignRef('is_hotjob', $is_hotjob);
        $this->assignRef('item', $item);
        $this->assignRef('fieldlist', $fieldList);
        /*$this->assignRef('appliedlist', $appliedList);*/
        $this->assignRef('lists', $lists);
                
        build_relation_value_JS();
    }
    
  	function adminedit(){  	    
  		global $option;
  		
  		$model = &$this->getModel();
  	    $item = &$this->get('Item');  	
  	   	
		$fieldList = &$this->get('AdminEditFieldList');
//		$item = parse_content_item($item, $fieldList);		
		$this->assignRef('fieldlist', $fieldList);
  	    $this->assignRef('option', $option);
  	    $this->assignRef('item', $item);
  	    parent::display();
	}    
    
    /**
      * Display view form
      */
    function show_job(){
    	
    	checkPermission('view_job_details');
        $user = JFactory::getUser();
    	$appliedList = getEditFieldList('ja_applications', ' and f.frontend_hidden=0', 1);
    	$this->assignRef('appfieldlist', $appliedList);
		
        $item = $this->get('Item');
        JRequest::setVar('user_id',$item->user_id);
        $profile = $this->get('ProfileFromUserId');
        $profile_editFiedlList = getEditFieldList('ja_profiles');
        $this->assignRef('profile_editFieldList', $profile_editFiedlList);
        $this->assignRef('profile', $profile);
        $this->assignRef('item', $item);
        
        
        $temp = $this->getModel('jajobs');
        $fieldList = $temp->getEditFieldList(' and f.frontend_hidden=0');
		$this->assignRef('fieldlist', $fieldList);
		$fromsearch = JRequest::getVar('fromsearch', 0);
		$this->assignRef('fromsearch', $fromsearch); 
		
        
        JRequest::setVar('job_id', $item->id);
        //$app = $this->get('AppItem');    
    	$app_postback = JRequest::getVar('app_postback',false);
    	if ($app_postback)
    	{
    		$post    = JRequest::getVar('apply_data');
    		$app->bind($post);
    	}   
    	
    	$mail_postback = JRequest::getVar('mail_postback',false);
    	if ($mail_postback)
    	{
    		$mail_data = array();
	    	$mail_data['youremail'] = JRequest::getVar('youremail');
	    	$mail_data['friendemail'] = JRequest::getVar('friendemail');
	    	$mail_data['subject'] = JRequest::getVar('subject');
	    	$mail_data['message'] = JRequest::getVar('message');
    	}    

    	$db = JFactory::getDBO();
    	$query = "SELECT * FROM #__ja_notes WHERE user_id=".(int)$user->id." and item_id=".(int)$item->id." and note_type='ja_jobs'";
    	$db->setQuery($query);
    	$note = $db->loadObject();
    	$this->assignRef('note', $note);
    	if (!$note)
    	{
    		require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'.DS.'ja_notes.php');
			$note = new JobBoardTableJA_Notes($db);
    	}
    	    
    	$this->assignRef('mail', $mail_data);
        //$this->assignRef('application', $app);
        
        $user = JFactory::getUser($item->user_id);
        $this->assign('user', $user);
    }
    
	function check_stared($id){
		$user = & JFactory::getUser();
		$db = & JFactory::getDBO();
		$table_name = 'ja_jobs';
		$query = 'SELECT id FROM #__ja_shortlist WHERE (user_id='.$user->id.') and (listtype="'.$table_name.'") and (item_id='.$id.')';
		$db->setQuery($query);
		$items = $db->loadObjectList();
		if ($items)
			return true;
		return false;		
	}
	
    function getToggleLink( $field_name, $row, $check=false, $imgY='Favorites-16x16.png', $imgX='favorite-remove-16x16.png', $prefix=''){
    	global $mainframe;
    	$img     = $check ? $imgY : $imgX;
        $task = $check ? "inactivate":"activate";
        $alt     = $check ? JText::_( 'REMOVE FAVORITE' ) : JText::_( 'SET AS FAVORITE' );
        $action  = $check ? JText::_( 'REMOVE FAVORITE' ) : JText::_( 'SET AS FAVORITE' );
                
        $href = '
        <a id = "hrf_'.$row->id.'" href="javascript:void(0);" onclick="return listItemTask(\''. $row->id .'\',\''. $field_name. '\',\''.$prefix.$task .'\')" title="'. $action .'">
        <img  id = "img_'.$row->id.'" src="'.JURI::base().'/components/com_jajobboard/images/'. $img .'" border="0" alt="'. $alt .'" /></a>'
        ;
        return $href;
    }
    
    function getListLimit($limit){
    	$array = array(5, 10, 15, 20, 50, 100);
    	$list_html = array();
    	foreach ($array as $value){
    		$list_html[] = JHTML::_('select.option', $value, $value);  
    	}
    	$layout = '';
    
    	$list_html = JHTML::_('select.genericlist',   $list_html, 'limit', 'class="inputbox" size="1" onchange="doSearch(\''.$this->layout.'\')"', 'value', 'text', $limit);
    	return $list_html;
    }
    
    function show_result_filter_job()
    {
  		global $mainframe, $option, $jbconfig, $permission;  
  		
  		/* Check permission */
  		checkPermission('view_list_jobs');
  		
        $model = &$this->getModel();   
        
        
        /* Get field select list */
  		$fieldEditList = $model->getEditFieldList(' and f.frontend_hidden=0 ');
       	$lists = $this->_getViewLists($fieldEditList);  
       	$this->assignRef('lists', $lists);
  		
       	// get data items
		$all_items = $model->search_job();
		$this->assignRef('all_items', $all_items);
                
        /* Paging */
       	$pagination = $this->get('Pagination');  //print_r($pagination);exit;
       	$this->assignRef('pagination', $pagination);
        
        /* Get field list */
        $fieldList = $model->getFieldList();       	
        $this->assignRef('fieldlist', $fieldList);		

        JRequest::setVar('is_jobfilter', true);
		
        $this->setLayout('jalist');
    }
    
    function show_result_jobalert()
    {
    	global $mainframe, $option, $jbconfig, $permission;  
  		
  		/* Check permission */
  		checkPermission('view_list_jobs');
  		
  		
  		// get data items
        $model = &$this->getModel();   
        
        
        /* Get field select list */
  		$fieldEditList = $model->getEditFieldList(' and f.frontend_hidden=0 ');
       	$lists = $this->_getViewLists($fieldEditList);  
       	$this->assignRef('lists', $lists);
  		
		$all_items = $model->show_result_jobalert();
		$this->assignRef('all_items', $all_items);
        
        
        /* Paging */
       	$pagination = $this->get('Pagination');  //print_r($pagination);exit;
       	$this->assignRef('pagination', $pagination);
        
        /* Get field list */
        $fieldList = $model->getFieldList();       	
        $this->assignRef('fieldlist', $fieldList);		

        JRequest::setVar('is_jobfilter', true);
		         
        $this->setLayout('jalist');
    }
    
    function multi_view()
    {
    	checkPermission('view_job_details');
    	$appliedList = getEditFieldList('ja_applications', ' and f.frontend_hidden=0', 1);
    	$this->assignRef('appfieldlist', $appliedList);
        $user = JFactory::getUser();
        $model = &$this->getModel();
    	$this->setLayout('jaview');
    	
        $items = $model->geItemView_List();
        
        $app_list = null;
        if ($user->id!=0 && $items)
        {
        	$arr_tmp = array();
        	for ($i=0;$i<count($items);$i++)
        		$arr_tmp[] = $items[$i]->id;
        	$str_job_id = implode(',',$arr_tmp);
        	$where = " and user_id='$user->id'";
        	if ($str_job_id)
        		$where .= " and job_id IN ($str_job_id)";
        	$app_list = $model->getAppForItemView($where);
        	$this->assignRef('app_list', $app_list);
        }
        else 
        {
        	$app_list = array();
        	$this->assignRef('app_list', $app_list);
        }
        
        $profile_list = array();
      
        if (count($items)>0){
        	$arr_profile = array();
        	for ($i=0;$i<count($items);$i++){
        		$arr_profile[$items[$i]->id] = $items[$i]->user_id;
        	}
        	$profile_list = $model->getProfileForItemView($arr_profile);        	
        }
        $this->assignRef('profile_list', $profile_list);

        $profile_editFiedlList = getEditFieldList('ja_profiles');
        $this->assignRef('profile_editFieldList', $profile_editFiedlList);
        $this->assignRef('items', $items);
        
        
        $temp = $this->getModel('jajobs');
        $fieldList = $temp->getEditFieldList(' and f.frontend_hidden=0');
		$this->assignRef('fieldlist', $fieldList);
		if (count($items)>0)
    	{
    		$arr_tmp = array();
        	for ($i=0;$i<count($items);$i++)
        		$arr_tmp[] = $items[$i]->id;
        	$str_job_id = implode(',',$arr_tmp);
        	$where = " and user_id='$user->id'";
        	if ($str_job_id)
        		$where .= " and item_id IN ($str_job_id)";
        	$notes = $model->getNoteForItemView($where);
        	$this->assignRef('notes', $notes);
    	}
    	/* Paging */
       	$pagination = &$this->get('Pagination');
       	$this->assignRef('pagination', $pagination);       	       	       	
    }
    
    function suggesturl()
    {
    	$result = $this->get('SuggestURL');
    	$this->assignRef('suggesturl',$result);
    }
    
    
	function displaycaptchaaddnew(){
		$captcha = new jacapcha();		
		$option = JRequest::getVar("type", "addnew");		
		$captcha->buildImage($option);
		exit;
	}	
    
	function getPostBack_Apply()
	{
		$db = JFactory::getDBO();
		require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'.DS.'ja_applications.php');
		$application = new JobBoardTableJA_Applications($db);
		$application->bind(JRequest::get('request'));
		return $application;
	}
	
	function display_searchform()
	{
		/* Check permission */
  		checkPermission('view_list_jobs');
		require_once(JPATH_COMPONENT_SITE.DS.'views'.DS.'jajobalerts'.DS.'view.html.php');
		$jobalert_view = new JobBoardViewJAJobAlerts();
		$objCategory = $jobalert_view->getCategoryCombo(array());
        $objLocation = $jobalert_view->getLocationCombo(array());
        $objPostedDate = $jobalert_view->getPostedDate('');
        $objJobType = $jobalert_view->getJobType('');
		$this->assignRef('objCategory',$objCategory);
        $this->assignRef('objLocation',$objLocation);
        $this->assignRef('objPostedDate',$objPostedDate);
        $this->assignRef('objJobType',$objJobType);
	}
	    
    function job_list_via_profiles()
    {
    	global $mainframe, $option, $jbconfig, $permission;  
    	$db = JFactory::getDBO();
  		
  		/* Check permission */
  		checkPermission('view_list_jobs');
  		
  		
  		// get data items
        $model = &$this->getModel();   
        
        
        /* Get field select list */
  		$fieldEditList = $model->getEditFieldList(' and f.frontend_hidden=0 ');
       	$lists = $this->_getViewLists($fieldEditList);  
       	$this->assignRef('lists', $lists);
       	

       	//Filter via profile
       	$cid = JRequest::getVar('cid');
       	
    	if (count($cid)>0)
    	{
    		$str_user_id = implode(',',$cid);
    		$query = "SELECT user_id FROM #__ja_profiles WHERE id IN ($str_user_id)";
    		$db->setQuery($query);
    		$result = $db->loadObjectList();
    		$temp_user_id = array();
    		for ($i=0;$i<count($result);$i++){
    			$temp_user_id[] = $result[$i]->user_id;
    		}
    		if( is_array($temp_user_id) )
    			$temp_user_id = implode(',',$temp_user_id);
    	}
  		
  		/* Get items list */ 		
        $limitstart = JRequest::getInt('limitstart', 0);
		$limit = JRequest::getInt('limit', $jbconfig['posts']->get('display_num'));
        
		$where_more  = '';
        $where_more .= ' and a.status=\'Approved\' ';
        $where_more .= ' AND ( a.expiry_date >= now() OR a.expiry_date is NULL ) and(a.effected_date<=now()) and ( (DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_display_days', 30). ' DAY) >= now()  AND a.is_hotjob=0) or (DATE_ADD(a.effected_date, INTERVAL '. (int)$jbconfig['posts']->get('posts_show_days_elapsed', 30). ' DAY) >= now()  AND a.is_hotjob=1) )';
        
        if($this->getLayout()=='jajobseekerlist'){
        	$items_id = $model->get_save_jobs_list();
        	if ($items_id==''||$items_id==null) $items_id='0';
        	$where_more .= " and a.id in ($items_id)";
        }
        
        	
//        echo $where_more;exit;

		if ( isset($temp_user_id) )
			$where_more .= " and a.user_id IN ($temp_user_id)";
		

        $all_items = $model->getItems($where_more, $limit, $limitstart);  
        $this->assignRef('all_items', $all_items);
        $item_notes = $model->getItemNotes($all_items);
        $this->assignRef('item_notes', $item_notes);
        
        /* Paging */
       	$pagination = &$this->get('Pagination');  
       	$this->assignRef('pagination', $pagination);
        
        /* Get field list */
        $where_more = '';
		if(!$mainframe->isAdmin()){
			$where_more = " and fl.admin_only!=1";
		}		
       	$fieldList = $model->getFieldList($where_more);       	
		$this->assignRef('fieldlist', $fieldList);		

    }
    
    function displayUploadFileForm()
    {
    	
    }
    function displayUploadFilePath()
    {
    	
    	$path = fileUpload(JRequest::getVar('field_name'),'applications',JRequest::getVar('field_type'));
    	if ($path!=JText::_ ( 'Size of uploaded file is too large' ) && $path!=JText::_ ( 'This file extension is not allowed to upload' ))
    	{
   			$this->assignRef('upload_file_path',$path)	;
   			$this->assign('is_success','done');
    	}
   		else 
   		{
   			$this->assign('is_success','error');
   			$this->assign('upload_file_path',$path)	;
   		}
    }
}
?>